package com.qujia.station.controller;

import com.qujia.common.core.domain.AjaxResult;
import com.qujia.station.domain.PayOrder;
import com.qujia.station.mapper.AppUserInfoMapper;
import com.qujia.station.service.IPayOrderAllService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/payOrderAll")
public class PayOrderAllController {



    @Autowired
    private IPayOrderAllService payOrderAllService;

    @Autowired
    private AppUserInfoMapper appUserInfoMapper;

    @Value("${test.param.task.enterpriseId:211}")
    private Long enterpriseId;

    @PostMapping("/add")
    public AjaxResult addPayOrderAll(@RequestBody PayOrder payOrder){
        if(Objects.isNull(payOrder)){
            return AjaxResult.success("请求参数异常");
        }
        payOrderAllService.addPayOrder(payOrder);
        return AjaxResult.success();
    }

    @PostMapping("/update")
    public AjaxResult updatePayOrderAll(@RequestBody PayOrder payOrder){
        if(Objects.isNull(payOrder)){
            return AjaxResult.success("请求参数异常");
        }
        payOrderAllService.updatePayOrder(payOrder);
        return AjaxResult.success();
    }

    @GetMapping("/refresh")
    public AjaxResult refresh(){
        payOrderAllService.addNewPayOrder();
        return AjaxResult.success();
    }

    @GetMapping("/executingGetTotalAmountByPayDate")
    public void getTotalAmountByPayDate() {

        LocalDateTime startTime = LocalDateTime.now().minusMonths(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
        LocalDateTime endTime = LocalDateTime.now().withDayOfMonth(1).minusDays(1).withHour(23).withMinute(59).withSecond(59);

        List<String> appUserMobilePhone = appUserInfoMapper.getAppUserMobilePhone(enterpriseId);
        payOrderAllService.getTotalAmountByPayDate(startTime,endTime,appUserMobilePhone);


    }
}
